import mock from '@/mock'
import data from './data/data'
export default {
  'post|/zzxt/api/getDangkeInfo': option => {
    const body = JSON.parse(option.body)
    const queryObject = body.params.queryObject
    const { page } = queryObject
    const value = queryObject.value
    switch (value[0]) {
      case 'local': {
        const result = mock.splitPage(Object.assign({ list: data.db_dangkedata_local }, page))
        return mock.toResult(result)
      }
      case 'else': {
        const result = mock.splitPage(Object.assign({ list: data.db_dangkedata_else }, page))
        return mock.toResult(result)
      }
    }
  },
  'post|/zzxt/api/deleteDangkeInfo': option => {
    const body = JSON.parse(option.body)
    const time = body.params.time
    var ArrayId = GetArrayId(time, data.db_dangkedata_local)
    data.db_dangkedata_local.splice(ArrayId, 1)
    return mock.toResult(null)
  },
  'post|/zzxt/api/postDangkeInfo': option => {
    debugger
    const body = JSON.parse(option.body)
    const formdata = body.params.FormData
    data.db_dangkedata_local.push(formdata)
    return mock.toResult(null)
  },
  'post|/zzxt/api/updateDangkeInfo': option => {
    const body = JSON.parse(option.body)
    const formdata = body.params.FormData
    const ArrayId = formdata.id
    data.db_dangkedata_local[ArrayId] = formdata
    return mock.toResult(null)
  },
}

function GetArrayId(time, db_data) {
  const length = db_data.length
  for (var i = 0; i < length; i++) {
    if (db_data[i].time === time) { return parseInt(i) }
  }
  return parseInt('-1')
}
